/**
 * Created by lipeng on 16/12/4.
 */

function isTYpe(type) {
  return function (obj) {
      if(typeof obj == type){
        return true;
      }else{
          return false;
      }
  }
};

var index = function (req,res) {
  var url = req.query.id ? req.query.id : 1;
    url = "id = "+url;
  var domaine = req.connection.remoteAddress;
    url = req.originalUrl;
  var url1 = req.url;
  var hostname = req.hostname;
  var ip = req.ip;
  var ips = req.ips;
  var isString = isTYpe('string');
  console.log(isString(121));
  res.append('Link', ['<http://learn-node.com>', '<http://learn-node.com:8080/>']);
    // res.attachment('../../images/1.jpg');
  res.download('/images/1.jpg',function (err) {
      if(err){
          console.log(err);
      }
  });
    // res.status(404).end();
    // res.redirect('http://baidu.com');
  res.render('index/index',{
      'name':'李鹏',
      'url':url,
      'domaine':domaine,
      'url1':url1,
      'hostname':hostname,
      'ip':ip,
      'ips':ips
  });
};

var store = function (req,res) {
    var username = req.body.username;
    // console.log(username);
    console.log(req.param('pwd'));
    res.end(username);
};
var info = function (req,res) {
    console.log(req.route);
    console.log(req.params.id);
    console.log(req.query.name.a);
    console.log(req.query.name);
    res.send('GET');
};
module.exports = {
  index:index,
  store:store,
  info:info
};